package com.zmzncs.lmtc.module.shop.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zmzncs.lmtc.common.pojo.PageInfo;
import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.util.JsonUtil;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.shop.pojo.shop_order.*;
import com.zmzncs.lmtc.module.shop.service.ShopOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商户-订单 前端控制器
 * </p>
 *
 * @author 高博文
 * @since 2021-05-20
 */
@Api(tags = "商户订单")
@RestController
@RequestMapping("/shop/shop-order")
public class ShopOrderController {

    @Autowired
    ShopOrderService shopOrderService;


    @ApiOperation(value = "分页")
    @GetMapping("page")
    public Rest<PageInfo<ShopOrderTableVO>> page(@Valid ShopOrderSearchForm form){
        IPage<ShopOrderDTO> iPage = shopOrderService.page(form);
        PageInfo<ShopOrderTableVO> pageInfo = JsonUtil.pageTransform(iPage, ShopOrderTableVO.class);

        return RestUtil.success(pageInfo);
    }

    @ApiOperation(value = "详情")
    @GetMapping("get-by-id")
    public Rest<ShopOrderVO> getById(@NotNull Long id){
        ShopOrderDTO shopOrderDTO = shopOrderService.getById(id);
        ShopOrderVO shopOrderVO = new ShopOrderVO();
        if (shopOrderDTO != null){
            BeanUtils.copyProperties(shopOrderDTO, shopOrderVO);
        }
        return RestUtil.success(shopOrderVO);
    }

    @ApiOperation(value = "查询打款信息")
    @GetMapping("get-payment")
    public Rest<PageInfo<OrderPaymentVO>> getPayment(@Valid OrderPaymentForm form){
        IPage<ShopOrderDTO> iPage = shopOrderService.getPayment(form);
        PageInfo<OrderPaymentVO> pageInfo = JsonUtil.pageTransform(iPage, OrderPaymentVO.class);
        return RestUtil.success(pageInfo);
    }

    @ApiOperation(value = "查询打款银行信息")
    @GetMapping("get-bank-info")
    public Rest<Map<String,BankInfoVo>> getBankInfo(@Validated OrderPaymentSelectForm form){
        form.validate();
        Map<String, BankInfoVo> map = shopOrderService.getBankInfo(form);
        return RestUtil.success(map);
    }

    @ApiOperation(value = "更新打款信息")
    @PostMapping("update-payment")
    public Rest updatePayment(@Validated OrderPaymentUpdateForm form){
        shopOrderService.updatePayment(form);
        return RestUtil.success();
    }



}

